﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercice2
    {
    class Program
        {
        static void Main(string[] args)
            {
            System.Console.Write("Enter a string : ");
            String str = System.Console.ReadLine();

            Int32 n = 0;
            try
                {
                System.Console.WriteLine("Convert.ToInteger");
                n = Convert.ToInt32(str);
                System.Console.WriteLine(n);
                }
            catch (Exception)
                {
                System.Console.WriteLine("Convert with Convert.ToInteger error !");
                }

            System.Console.WriteLine("");

            try
                {
                System.Console.WriteLine("Convert.ToDecimal + Cast Int32");
                n = (Int32)Convert.ToDecimal(str);
                System.Console.WriteLine(n);
                }
            catch (Exception)
                {
                System.Console.WriteLine("Convert with Convert.ToDecimal error !");
                }
            System.Console.WriteLine("");

            try
                {
                System.Console.WriteLine("Int32.TryParse");
                if (Int32.TryParse(str, out n))
                    {
                    System.Console.WriteLine(n);
                    }
                else
                    {
                    System.Console.WriteLine("Convert with TryParse error !");
                    }

                }
            catch (Exception)
                {
                System.Console.WriteLine("Convert with TryParse error !");
                }
            System.Console.WriteLine("");
            System.Console.WriteLine("final value = {0:n}", n);
            System.Console.WriteLine("");

            try
                {
                System.Console.WriteLine(System.Math.Pow(n, 2));
                }
            catch (Exception)
                {
                System.Console.WriteLine("error pow");
                }
            

            System.Console.ReadKey();
            }
        }
    }
